<?php
include('config.php');
if(!isset($_COOKIE[md5('islogin')])){
include("login.php");
die();
}

if(@$_GET['do']=="out"){
$cookietime=time()-3600;
setcookie(md5('islogin'), "1", $cookietime,"/");
echo('<script type="text/javascript">alert("成功退出");window.location.href="admin.php?out=1";</script>');
}

if(!empty($_GET['add'])){
    @$fp = fopen(DATA_F,"a");
    
    if(!$fp){
        echo "system error";
        exit();
    }else {
      $fileData = $_POST['url'] . "<>" . $_POST['name'] . "<>" . $_POST['desc'] . "<>" . $_POST['keyword'] . "\r\n";
           
            fwrite($fp,$fileData);
            fclose($fp);
    }
echo('<script type="text/javascript">alert("添加成功！");window.location.href="admin.php";</script>');
}
$pageinfo=1;
$perpage=20;
if(!isset($_GET['page'])){
$pages = $pageinfo;
}
if(isset($pages)){
$pageinfox=$perpage*$pages;
$pageinfoy=$pageinfox-$perpage;
$pageinfo=$pages;
}


?>
<html>
<head>
    <meta charset="utf-8">
    <title>后台管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="bootstrap.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="//cdnjs.bootcss.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
    <![endif]-->
	<style type="text/css">
      body {
		font-family:Microsoft Yahei,Simhei !important;
        padding-top: 20px;
        padding-bottom: 40px;
      }

      .container-narrow {
        margin: 0 auto;
        max-width: 1024px;
      }
    </style>
	</head>
  <body>
    <div class="container-narrow">

      <div class="masthead">
        <ul class="nav nav-pills pull-right">
          <li class="active"><a href="#">后台</a></li>
          <li><a href="?do=out">退出</a></li>
        </ul>
        <h3 class="muted">后台管理</h3>
      </div>

      <hr>
<?php if(!empty($msg))echo $msg;?>
      <div class="jumbotron">
        增加网址<br/>
		<form method="post" action="?add=add">
		<input type="text" placeholder="名称" name="name">
		<input type="text" placeholder="网址，带http" name="url">
		<input type="text" placeholder="关键词" name="keyword">
		<br/>描述<br/>
		<textarea rows="2" style="width:61%" name="desc"></textarea><br/>
        <button class="btn btn-success">提交</button>
		</form>
      </div>

      <hr>

      <div class="row-fluid marketing">
<?PHP
echo "<table border='1' class='dataintable'>
<tr>
<th>网站名</th>
<th>网址</th>
<th>操作</th>
</tr>";
$i=0;
$admin_data = array();
foreach ($zxs_data as $value) {
    $value = explode("<>",$value);
	$row[] = $value;
}
foreach($zxsblog_data as $row)
  {
  if(isset($row['3'])){
  echo "<tr>";
  echo "<td>" . $row['1'] . "</td>";
  echo "<td>" . $row['0'] . "</td>";
  ?>
<td style='width: 74px;'><a href='admin2.php?do=del&x=<?php echo $row['0'];?>' onclick="if(confirm('确定删除?\n这项操作是无法挽回的！')==false)return false;">删除</a>&nbsp;&nbsp;<a href='admin2.php?do=edit&x=<?php echo $row['0']?>'>修改</a></td>
<?php
  echo "</tr>";
  $i++;
  }
  }
echo "</table>";
?>
      </div>

      <hr>

      <div class="footer">
        <p>©中学生站长联盟&快乐家园 2013</p>
      </div>

    </div> <!-- /container -->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="//cdnjs.bootcss.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="bootstrap.js"></script>

  

</body></html>